package com.haiertvbic.tvnow.widget;

import java.util.TimerTask;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.BaseAdapter;

import com.haiertvbic.tvnow.model.ProgramBean;
import com.haiertvbic.tvnow.network.EPGWeb;
import com.haiertvbic.tvnow.util.Constant;
import com.haiertvbic.tvnow.util.SLog;

public class MyProgram {
	protected static final String TAG = "MyProgram";
	public ProgramBean pro;
	private BaseAdapter adapter;
	private Context context;
	private String cid;
	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 11:
				pro = (ProgramBean) msg.obj;
				adapter.notifyDataSetChanged();
				break;

			default:
				break;
			}
		};
	};

	public MyProgram(BaseAdapter adapter, Context context, String cid) {
		super();
		this.adapter = adapter;
		this.context = context;
		this.cid = cid;
		getPic();
	}

	// 定时取节目的

	private void getPic() {
		if (Constant.PIC_TT!=null) {
			Constant.PIC_TT.schedule(new TimerTask() {
				private ProgramBean pro;

				@Override
				public void run() {
					pro = EPGWeb.getCurrentProgram(context, cid);
					if (pro!=null) {
						Message msg = Message.obtain();
						msg.what = 11;
						msg.obj = pro;
						handler.sendMessage(msg);
						SLog.d(TAG, "执行一个获取当前频道节目"+cid+"任务");
					}else {
						SLog.d(TAG, "pro为空=======");
					}
				}
			}, 0, 1000 * 30);
		}
	
	}
}
